<?php
// +----------------------------------------------------------------------
// | CoreThink [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.corethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: jry <598821125@qq.com> <http://www.corethink.cn>
// +----------------------------------------------------------------------
namespace Wap\Controller;

use Think\Controller;
use Com\DingdingAuth;
/**
 * 后台控制器
 */
class IndexController extends WapController
{
	
	/**
	 * 钉钉
	 * 获取用户信息
	 */
	public function get_userinfo()
	{
	
// 		$Auth=new \Auth();
// 		$User=new \User();
// 		$accessToken = $Auth->getAccessToken();
		$code = I("code");
		//$userInfo = $User->getUserInfo($accessToken, $code);
		//Log::i("[USERINFO]".json_encode($userInfo));
		//$user=json_decode($userInfo,true);
		$corpid=C('CORPID');
		$corpsecret=C('SECRET');
		$D=new DingdingAuth($corpid, $corpsecret);
		$token = $D->getAccessToken();
			$param1=array(
    				'code'=>$code
    		);
    		$userInfo=$D->getDingRe("user/getuserinfo",'','GET',$param1);
		    		
    		$param=array(
    				'userid'=>$userInfo['userid'],
    		);
    		$user_all=$D->getDingRe("user/get",'','GET',$param);
    		
    		session('DING_USER',$user_all);
		
		echo json_encode($userInfo,true);
		
	}
	/**
	 * loading页面
	 */
    public function index()
    {
    	    	
    	$this->assign('meta_title', 'loading...');
    	$this->display();
		
    }
    /**
     * 首页
     */
    public function shouye()
    {
    	$user_info=session('DING_USER');
    	if (!$user_info) {
    		header('Location: '.U('Wap/Index/index'));
    	}
    	
    	$this->assign('user_info', $user_info);
    	$this->assign('meta_title', '首页');
    	$this->display();
    
    }
  


    
    
}   
